package com.itheima.common;

import com.alibaba.fastjson2.annotation.JSONField;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * <h1>分页结果对象</h1>
 *
 * @author <a href="515857087@qq.com">叶世铭</a>
 * @since 2022/11/2
 */

@ApiModel("分页结果对象")
public class Paging<T> implements Serializable {
    private static final Logger log = LoggerFactory.getLogger(Paging.class);
    private static final long serialVersionUID = 4784961132604516495L;
    @ApiModelProperty("总行数")
    @JSONField(
            name = "count"
    )
    @JsonProperty("count")
    private long count = 0L;
    @ApiModelProperty("数据列表")
    @JSONField(
            name = "list"
    )
    @JsonProperty("list")
    private List<T> list = Collections.emptyList();
    @ApiModelProperty("页码")
    @JSONField(
            name = "page"
    )
    @JsonProperty("page")
    private Long page;
    @ApiModelProperty("页大小")
    @JSONField(
            name = "perPage"
    )
    @JsonProperty("perPage")
    private Long perPage;
    @ApiModelProperty("总页数")
    @JSONField(
            name = "pageCount"
    )
    @JsonProperty("pageCount")
    private Long pageCount;

    public Paging() {
    }

    public Paging(IPage<T> page) {
        this.count = page.getTotal();
        this.list = page.getRecords();
        this.page = page.getCurrent();
        this.perPage = page.getSize();
        this.pageCount = page.getPages();
    }

    public long getCount() {
        return this.count;
    }

    public List<T> getList() {
        return this.list;
    }

    public Long getPage() {
        return this.page;
    }

    public Long getPerPage() {
        return this.perPage;
    }

    public Long getPageCount() {
        return this.pageCount;
    }

    @JsonProperty("count")
    public void setCount(long count) {
        this.count = count;
    }

    @JsonProperty("list")
    public void setList(List<T> list) {
        this.list = list;
    }

    @JsonProperty("page")
    public void setPage(Long page) {
        this.page = page;
    }

    @JsonProperty("perPage")
    public void setPerPage(Long perPage) {
        this.perPage = perPage;
    }

    @JsonProperty("pageCount")
    public void setPageCount(Long pageCount) {
        this.pageCount = pageCount;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof Paging)) {
            return false;
        } else {
            Paging<?> other = (Paging)o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.getCount() != other.getCount()) {
                return false;
            } else {
                label61: {
                    Object this$page = this.getPage();
                    Object other$page = other.getPage();
                    if (this$page == null) {
                        if (other$page == null) {
                            break label61;
                        }
                    } else if (this$page.equals(other$page)) {
                        break label61;
                    }

                    return false;
                }

                label54: {
                    Object this$perPage = this.getPerPage();
                    Object other$perPage = other.getPerPage();
                    if (this$perPage == null) {
                        if (other$perPage == null) {
                            break label54;
                        }
                    } else if (this$perPage.equals(other$perPage)) {
                        break label54;
                    }

                    return false;
                }

                Object this$pageCount = this.getPageCount();
                Object other$pageCount = other.getPageCount();
                if (this$pageCount == null) {
                    if (other$pageCount != null) {
                        return false;
                    }
                } else if (!this$pageCount.equals(other$pageCount)) {
                    return false;
                }

                Object this$list = this.getList();
                Object other$list = other.getList();
                if (this$list == null) {
                    if (other$list != null) {
                        return false;
                    }
                } else if (!this$list.equals(other$list)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof Paging;
    }

    public int hashCode() {
        int result = 1;
        long $count = this.getCount();
        result = result * 59 + (int)($count >>> 32 ^ $count);
        Object $page = this.getPage();
        result = result * 59 + ($page == null ? 43 : $page.hashCode());
        Object $perPage = this.getPerPage();
        result = result * 59 + ($perPage == null ? 43 : $perPage.hashCode());
        Object $pageCount = this.getPageCount();
        result = result * 59 + ($pageCount == null ? 43 : $pageCount.hashCode());
        Object $list = this.getList();
        result = result * 59 + ($list == null ? 43 : $list.hashCode());
        return result;
    }

    public String toString() {
        long var10000 = this.getCount();
        return "Paging(count=" + var10000 + ", list=" + this.getList() + ", page=" + this.getPage() + ", perPage=" + this.getPerPage() + ", pageCount=" + this.getPageCount() + ")";
    }
}
